#e
#Title[ũGx[^[v]
#Text[]
#Image[]
#BackGround[]
#BGM[]
#PlayLevel[Extra]
#ScriptVersion[2]
#Player[FREE]


script_enemy_main
{
let apx=GetX;
let bpx=GetX;
let cpx=GetX;
let dpx=GetX;
let ax=GetX;
let bx=GetX;
let cx=GetX;
let dx=GetX;
let ay=GetY;
let by=GetY;
let cy=GetY;
let dy=GetY;

	//GoɈxs镔
	@Initialize
	{
	//   eϐ

	//   XyJ[hf[^
	SetLife(1000);
	SetScore(300000);
	SetDamageRate(0,  0);
	SetTimer(73);
	SetInvincibility(250);
	SetDurableSpellCard();
	SetEnemyMarker(false);
	LoadGraphic("script\img\ExRumia.png");
	LoadUserShotData(GetCurrentScriptDirectory~"..\img\usershot.txt");
	CutIn(KOUMA,"ũGx[^[v",GetCurrentScriptDirectory~"..\img\cutin09.png",0,0,255,320);
	}
	//ʒu܂ňړ
	SetMovePosition02(GetCenterX, GetCenterY, 60);

	BG_Standard;
	GraphicControl;
	AtackTaskA;
	AtackTaskB;
	AtackTaskC;
	AtackTaskD;
	AtackTaskE;
	MoveTaskA;
	MoveTaskB;
	MoveTaskC;
	MoveTaskD;
	//MoveTask;

	//G̃Ct0ɂȂ܂ŁA̕1t[1s
	@MainLoop
	{
		yield;



	}
	
	//`惋[vB1t[1s
	@DrawLoop
	{
		SetColor(255,255,255);
		SetAlpha(127);
		SetTexture("script\img\ExRumia.png");//摜͔q

		SetGraphicRect(0,1,63,64);
		if(ax<apx-1){
			SetGraphicRect(128,1,191,64);
		}
		if(ax>apx+1){
			SetGraphicRect(192,1,255,64);
		}
		DrawGraphic(ax,ay);

		SetGraphicRect(0,1,63,64);
		if(bx<bpx-1){
			SetGraphicRect(128,1,191,64);
		}
		if(bx>bpx+1){
			SetGraphicRect(192,1,255,64);
		}
		DrawGraphic(bx,by);

		SetGraphicRect(0,1,63,64);
		if(cx<cpx-1){
			SetGraphicRect(128,1,191,64);
		}
		if(cx>cpx+1){
			SetGraphicRect(192,1,255,64);
		}
		DrawGraphic(cx,cy);

		SetGraphicRect(0,1,63,64);
		if(dx<dpx-1){
			SetGraphicRect(128,1,191,64);
		}
		if(dx>dpx+1){
			SetGraphicRect(192,1,255,64);
		}
		DrawGraphic(dx,dy);
	}
		
	//GłuԂɈxs镔
	@Finalize
	{
		DeleteGraphic("script\img\ExRumia.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back1.png");
		DeleteGraphic(GetCurrentScriptDirectory ~"..img\back2.png");
	}
	//XyJ[h̔wi
	//Ă悢
	@BackGround
	{
		BG_Simple;
	}

	task AtackTaskA{
		wait(420);
		let dir=rand(0,360);
		loop(4){
			let tdir=rand(0,360);
			YggdrasillBit(dir,30,cos(tdir)*200+GetCenterX,sin(tdir)*200+GetCenterY,1);
			wait(20);
			dir+=90;
		}
		wait(2700);
		loop{
			dir=rand(0,360);
			loop(8){
				MadballLaser(ax,ay,dir,atan2(GetPlayerY-ay,GetPlayerX-ax),20,0.5,1,20,400,80,220,300,BLUE01,120);
				dir+=45;
			}
			wait(400);
		}

	}
	task MoveTaskA{
		let mt=60;
		let mx=(GetCenterX-ax)/mt;
		let my=(GetCenterY-ay)/mt;
		loop(mt){ax+=mx;ay+=my;yield;}
		wait(60);
		mx=(GetCenterX-120-ax)/mt;
		my=(GetCenterY+180-ay)/mt;
		loop(mt){ax+=mx;ay+=my;yield;}
		mx=0;
		my=-(GetCenterY-GetClipMinY)/120;
		mt=120;
		loop(mt){ax+=mx;ay+=my;yield;}
		my=0-my;
		mt=60;
		loop(mt){ax+=mx;ay+=my;yield;}
		mx=(GetCenterX-ax)/mt;
		my=(GetCenterY-50-ay)/mt;
		loop(mt){ax+=mx;ay+=my;yield;}
		wait(540);
		loop(mt){ax-=mx;ay-=my;yield;}
		wait(2120);
		mx=(GetCenterX-ax)/mt;
		my=(GetCenterY-60-ay)/mt;
		loop(mt){ax+=mx;ay+=my;yield;}

	}

	task AtackTaskB{
		wait(1020);
		loop(200){
			PhantomShot(bx,by,1,rand(0,360),rand_int(RED22,ORANGE22),30,true);
			PhantomShot(bx,by,1,rand(0,360),rand_int(RED22,ORANGE22),30,false);
			wait(3);
		}
		wait(1600);
		loop{
			PhantomShot(bx,by,1,rand(0,360),rand_int(RED22,ORANGE22),30,true);
			PhantomShot(bx,by,1,rand(0,360),rand_int(RED22,ORANGE22),30,false);
			wait(10);
		}
	}
	task MoveTaskB{
		let mt=60;
		let mx=(GetCenterX-bx)/mt;
		let my=(GetCenterY-by)/mt;
		loop(60){bx+=mx;by+=my;yield;}
		wait(60);
		mx=(GetCenterX-120-bx)/mt;
		my=(GetCenterY+50-by)/mt;
		loop(60){bx+=mx;by+=my;yield;}
		mx=0;
		my=-(GetCenterY-GetClipMinY)/120;
		mt=120;
		loop(mt){bx+=mx;by+=my;yield;}
		my=0-my;
		mt=60;
		loop(mt){bx+=mx;by+=my;yield;}
		wait(600);
		mx=(GetCenterX-bx)/mt;
		my=(GetCenterY-50-by)/mt;
		loop(mt){bx+=mx;by+=my;yield;}
		wait(600);
		loop(mt){bx-=mx;by-=my;yield;}

	}
	
	task AtackTaskC{
		wait(1740);
		let nwaya=16;
		let cnt=0;
		let wt=50;
		loop{
			let dir=rand(0,360);
			loop(nwaya){
				CreateShotA(0,cx,cy,20);
				SetShotDataA(0,0,1,dir,0,-0.02,0,BLUE12);
				SetShotKillTime(0,61);

				CreateShotA(1,0,0,20);
				SetShotDataA(1,0,1,dir+45,0,-0.02,0,BLUE12);
				SetShotKillTime(1,61);

				CreateShotA(2,0,0,20);
				SetShotDataA(2,0,1,dir,0,-0.02,0,BLUE12);
				SetShotKillTime(2,61);
				CreateShotA(3,0,0,20);
				SetShotDataA(3,0,1,dir+60,0,0,0,BLUE12);
				AddShot(60,2,3,0);
				CreateShotA(3,0,0,20);
				SetShotDataA(3,0,1,dir,0,0,0,BLUE12);
				AddShot(60,2,3,0);
				AddShot(60,1,2,0);
				AddShot(60,0,1,0);

				CreateShotA(1,0,0,20);
				SetShotDataA(1,0,1,dir-45,0,-0.02,0,RED12);
				SetShotKillTime(1,61);
				CreateShotA(2,0,0,20);
				SetShotDataA(2,0,1,dir+45,0,-0.02,0,RED12);
				SetShotKillTime(2,61);
				CreateShotA(3,0,0,20);
				SetShotDataA(3,0,1,dir-60,0,0,0,RED12);
				AddShot(60,2,3,0);
				CreateShotA(3,0,0,20);
				SetShotDataA(3,0,1,dir,0,0,0,RED12);
				AddShot(60,2,3,0);
				AddShot(60,1,2,0);
				AddShot(60,0,1,0);

				FireShot(0);
				dir+=360/nwaya;
			}
			cnt++;
			if(cnt==8){wt=1200;}
			if(cnt==9){wt=120;}
			wait(wt);
		}
	}
	task MoveTaskC{
		let mt=60;
		let mx=(GetCenterX-cx)/mt;
		let my=(GetCenterY-cy)/mt;
		loop(mt){cx+=mx;cy+=my;yield;}
		wait(60);
		mx=(GetCenterX+120-cx)/mt;
		my=(GetCenterY+180-cy)/mt;
		loop(mt){cx+=mx;cy+=my;yield;}
		mx=0;
		my=-(GetCenterY-GetClipMinY)/120;
		mt=120;
		loop(mt){cx+=mx;cy+=my;yield;}
		my=0-my;
		mt=60;
		loop(mt){cx+=mx;cy+=my;yield;}
		wait(1260);
		mx=(GetCenterX-cx)/mt;
		my=(GetCenterY-50-cy)/mt;
		loop(mt){cx+=mx;cy+=my;yield;}
		wait(600);
		loop(mt){cx-=mx;cy-=my;yield;}
		wait(800);
		mx=(GetCenterX+120-cx)/mt;
		my=(GetCenterY-60-cy)/mt;
		loop(mt){cx+=mx;cy+=my;yield;}

	}
	task AtackTaskD{
		wait(2520);
		let cnt=0;
		let wt=60;
		loop{
			let dir=atan2(GetPlayerY-dy,GetPlayerX-dx);
			let bd=0;
			while(bd==0){
				dx+=cos(dir)*10;
				dy+=sin(dir)*10;
				CreateShot02(dx,dy,0,dir,0.05,2,YELLOW01,40);
				if(dx<GetClipMinX+60||dx>GetClipMaxX-60||dy<GetCenterY-80||dy>GetCenterY+80){
					dx-=cos(dir)*10;
					dy-=sin(dir)*10;
					bd++;
				}

				dx+=cos(dir)*10;
				dy+=sin(dir)*10;
				CreateShot02(dx,dy,0,dir,0.05,2,YELLOW02,40);
				if(dx<GetClipMinX+60||dx>GetClipMaxX-60||dy<GetCenterY-80||dy>GetCenterY+80){
					dx-=cos(dir)*10;
					dy-=sin(dir)*10;
					bd++;
				}
			}
			cnt++;
			if(cnt==6){wt=30;}
			if(cnt==15){wt=240;}
			wait(wt);
		}
	}
	task MoveTaskD{
		let mt=60;
		let mx=(GetCenterX-dx)/mt;
		let my=(GetCenterY-dy)/mt;
		loop(mt){dx+=mx;dy+=my;yield;}
		wait(60);
		mx=(GetCenterX+120-dx)/mt;
		my=(GetCenterY+50-dy)/mt;
		loop(mt){dx+=mx;dy+=my;yield;}
		mx=0;
		my=-(GetCenterY-GetClipMinY)/120;
		mt=120;
		loop(mt){dx+=mx;dy+=my;yield;}
		my=0-my;
		mt=60;
		loop(mt){dx+=mx;dy+=my;yield;}
		wait(2100);
		mx=(GetCenterX-dx)/mt;
		my=(GetCenterY-50-dy)/mt;
		loop(mt){dx+=mx;dy+=my;yield;}

	}

	task AtackTaskE{	//̃[U[
		wait(60);
		CreateLaserA(0,-50,GetClipMinY,500,32,21,0);
		SetLaserDataA(0,0,0,0,0,0,90);
		SetLaserDataA(0,50,0,0,0,(GetCenterY-GetClipMinY)/60,90);
		SetLaserDataA(0,120,0,0,0,0,90);
		SetShotKillTime(0,121);
		FireShot(0);
		wait(60);
		Elevator(GetClipMinX+20,GetCenterY,0,360);
		Elevator(GetClipMaxX-20,GetCenterY,90,240);
		Elevator(GetClipMaxX-20,GetClipMaxY,180,360);
		Elevator(GetClipMinX+20,GetClipMaxY,270,240);
		wait(240);
		//ȉAEĎB
		loop{
			if(GetPlayerY<130||GetPlayerY>350){
				CreateLaserA(0,-50,GetClipMinY,500,32,21,0);
				SetLaserDataA(0,0,0,0,0,2,90);
				SetShotKillTime(0,56);
				FireShot(0);
				CreateLaserA(0,-50,GetClipMaxY,500,32,21,0);
				SetLaserDataA(0,0,0,0,0,-2,90);
				SetShotKillTime(0,56);
				FireShot(0);
			}
			wait(50);
		}

	}
	task Elevator(
		x,
		y,
		dir,
		long
	){
		let obj=Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,dir);
		Obj_SetSpeed(obj,0);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetGraphic(obj,21);
		ObjShot_SetDelay(obj,30);
		ObjShot_SetBombResist(obj,true);
		ObjLaser_SetLength(obj,long);
		ObjLaser_SetWidth(obj,32);
		wait(60);
		loop(120){
			y-=(GetCenterY-GetClipMinY)/120;
			Obj_SetY(obj,y);
			yield;
		}
		loop(60){
			y+=(GetCenterY-GetClipMinY)/120;
			Obj_SetY(obj,y);
			yield;
		}
	}

	task PhantomShot(	//@ɋ߂ÂƖ{͔ZȂAU͔ȂeB
		x,
		y,
		speed,
		angle,
		graph,
		delay,
		tf		//^U
	){
		//e^XN
		let obj = Obj_Create(OBJ_SHOT);//eIuWFNg쐬
		Obj_SetX(obj, x);//xWݒ
		Obj_SetY(obj, y);//yWݒ;
		Obj_SetSpeed(obj, speed);//xݒ
		Obj_SetAngle(obj, angle);//ړpxݒ
		ObjShot_SetGraphic(obj, graph);//摜ݒ
		ObjShot_SetDelay(obj, delay);//xԐݒ
		Obj_SetCollisionToPlayer(obj, tf);

		while(!Obj_BeDeleted(obj)){
			let distance=Distance(Obj_GetX(obj),Obj_GetY(obj),GetPlayerX,GetPlayerY);
			if(distance<96){
				if(tf==true){
					Obj_SetAlpha(obj,255);
				}
				else{
					Obj_SetAlpha(obj,distance*3-30);
				}
			}
			if(distance>=96){
				if(tf==false){
					Obj_SetAlpha(obj,255);
				}
				else{
					Obj_SetAlpha(obj,480-distance*3);
				}
			}
			yield;
		}
	}

	task YggdrasillBit(
		dir,	//ˌ
		dis,
		tx,	//zu
		ty,
		grf
	){
		let x=cos(dir)*30+ax;
		let y=sin(dir)*30+ay;
		let sx=x;
		let sy=y;
		let obj=Obj_Create(OBJ_LASER);
		let movespd=Distance(x,y,tx,ty)/120;
		let movedir=atan2(ty-y,tx-x);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetGraphic(obj,11);
		ObjShot_SetBombResist(obj,true);
		ObjShot_SetDelay(obj,65535);
		ObjLaser_SetWidth(obj,20);
		ObjLaser_SetSource(obj,false);

		let bullet=Obj_Create(OBJ_SHOT);
		Obj_SetAutoDelete(bullet,false);
		Obj_SetAlpha(bullet,96);
		Obj_SetCollisionToPlayer(bullet,false);
		ObjShot_SetGraphic(bullet,grf);
		loop(120){
			sx=cos(dir)*dis+ax;
			sy=sin(dir)*dis+ay;
			Obj_SetPosition(obj,x,y);
			Obj_SetPosition(bullet,x,y);
			Obj_SetAngle(obj,atan2(sy-y,sx-x));
			ObjLaser_SetLength(obj,Distance(x,y,sx,sy));
			x+=cos(movedir)*movespd;
			y+=sin(movedir)*movespd;
			dir+=0.5;
			yield;
		}
		loop(3){
			movespd=0;
			movedir=atan2(GetPlayerY-y,GetPlayerX-x);
			Obj_SetAlpha(bullet,255);
			Obj_SetCollisionToPlayer(bullet,true);
			loop(50){
				sx=cos(dir)*dis+ax;
				sy=sin(dir)*dis+ay;
				Obj_SetPosition(obj,x,y);
				Obj_SetPosition(bullet,x,y);
				Obj_SetAngle(obj,atan2(sy-y,sx-x));
				ObjLaser_SetLength(obj,Distance(x,y,sx,sy));
				x+=cos(movedir)*movespd;
				y+=sin(movedir)*movespd;
				dir+=0.5;
				CreateShotA(0,x,y,0);
				SetShotDataA(0,0,0,0,0,0,0,grf);
				SetShotKillTime(0,6);
				FireShot(0);
				if(movespd<=6){movespd+=0.6;}
				yield;
			}
			loop(10){
				sx=cos(dir)*dis+ax;
				sy=sin(dir)*dis+ay;
				Obj_SetPosition(obj,x,y);
				Obj_SetPosition(bullet,x,y);
				Obj_SetAngle(obj,atan2(sy-y,sx-x));
				ObjLaser_SetLength(obj,Distance(x,y,sx,sy));
				x+=cos(movedir)*movespd;
				y+=sin(movedir)*movespd;
				dir+=0.5;
				CreateShotA(0,x,y,0);
				SetShotDataA(0,0,0,0,0,0,0,grf);
				SetShotKillTime(0,6);
				FireShot(0);
				movespd-=0.6;
				yield;
			}
			Obj_SetAlpha(bullet,96);
			Obj_SetCollisionToPlayer(bullet,false);
			movespd=1;
			movedir=atan2(GetPlayerY-y,GetPlayerX-x);
			loop(60){
				sx=cos(dir)*dis+ax;
				sy=sin(dir)*dis+ay;
				Obj_SetPosition(obj,x,y);
				Obj_SetPosition(bullet,x,y);
				Obj_SetAngle(obj,atan2(sy-y,sx-x));
				ObjLaser_SetLength(obj,Distance(x,y,sx,sy));
				x+=cos(movedir)*movespd;
				y+=sin(movedir)*movespd;
				dir+=0.5;
				yield;
			}
		}
		Obj_Delete(obj);
		Obj_Delete(bullet);
	}
	task MadballLaser(
		x,	//]̒S
		y,
		dira,	//[U[̊px
		dirb,	//[U[̊px
		dis,
		expand,
		rot,
		wide,
		long,
		opentime,
		closetime,	//n߂鎞
		killtime,
		grf,
		delay
	){
		let obj=Obj_Create(OBJ_LASER);
		Obj_SetAngle(obj,dirb);
		ObjShot_SetGraphic(obj,grf);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetWidth(obj,wide);
		ObjLaser_SetLength(obj,long);
		let cnt=0;
		loop(killtime){
			if(cnt<=opentime){dis+=expand;}
			cnt++;
			if(cnt>closetime){dis-=expand;}
			dira+=rot;
			Obj_SetPosition(obj,cos(dira)*dis+x,sin(dira)*dis+y);
			yield;
		}
		Obj_Delete(obj);
	}

	task GraphicControl{
		loop{
			apx=ax;
			bpx=bx;
			cpx=cx;
			dpx=dx;
			yield;
		}
	}

	#include_function".\function.txt"
}

